package org.ala.tcp_feign_client.spring.feign.results.impl;

import org.ala.tcp_feign_client.ITcpFeignCallback;
import org.ala.tcp_feign_client.spring.feign.results.ITcpFeignClientResultsMapper;
import org.ala.tcp_feign_common.exceptions.SerializableException;
import org.ala.tcp_feign_common.msg.biz_resp.BizRespByteMessage;


/**
 * 异步回调
 * <p>	需要额外提供timeout机制（服务端没给返回值的情况，msgId会一直在map里）
 *
 * @author 骆毅(ala)
 * @date 2024年4月24日
 */
public class BizRespResultAsyncCallback extends AbstractBizRespResultCallback {

	
	/**
	 * 异步回调
	 */
	@SuppressWarnings("rawtypes")
	protected ITcpFeignCallback callback;
	
	
	public BizRespResultAsyncCallback(long msgId, long timeout, ITcpFeignClientResultsMapper resultsMapper) {
		super(msgId, timeout, resultsMapper);
	}
	
	
	@SuppressWarnings("unchecked")
	@Override
	public void triggeCallback(BizRespByteMessage msg) throws SerializableException {
		Object resp = buildResp(msg);
		callback.callback(resp);
	}
	@Override
	public void triggeTimeout() {
		callback.timeout();
	}


	@SuppressWarnings("rawtypes")
	public ITcpFeignCallback getCallback() {
		return callback;
	}
	@SuppressWarnings("rawtypes")
	public void setCallback(ITcpFeignCallback callback) {
		this.callback = callback;
	}

}
